//get query variables from the current URL
var QueryString = function () {
  // This function is anonymous, is executed immediately and
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(pair[1]);
    }
  }
    return query_string;
} ();

jQuery( function(){

	// Add search query to search input and search page title.
	if(jQuery('.page-id-3294').length) {
		var default_gsq = QueryString.q;
		var gsq = default_gsq.replace(/[+]/g, ' ');

		jQuery('.entry-header .entry-title').append(' for "<em>' + gsq + '</em>"');
		jQuery('#searchform #q').attr('value', gsq);
		jQuery('#searchform label').hide();
	}

	/* searchform prpagate cliks on label to input so the label dissapears as expected */
	jQuery('#searchform label').click(function(){
		jQuery( '#q', jQuery(this).parent() ).focus();
	});


	/* featured carousel */
	if( jQuery('#featured-posts').length != 0 ){
		jQuery('#featured-posts').jcarousel({
			'animation' : 500,
			'itemVisibleInCallback' : { onBeforeAnimation: addictiveLoadImages }
		});

		/* fade images when loading */
		jQuery('#featured-posts img').bind('load', function () {
			jQuery(this).css('visibility','visible').hide().fadeIn('slow');
		});
	}


	/* load facebook like box */
	loadFaceBox();

	/* go to top */
	jQuery('#go-to-top').click(function(e){
		e.preventDefault();
		goToByScroll('wrapper');
	});


	/* scroll nav bar */

	/* var innHedOHeight = jQuery("#inner-header").outerHeight();

	if( innHedOHeight <= jQuery(window).scrollTop() )
		jQuery( '#nav-bar' ).addClass( 'scroll' );

	jQuery(window).scroll( function(){
		if( innHedOHeight <= jQuery(window).scrollTop() )
			jQuery( '#nav-bar' ).addClass( 'scroll' );
		else
			jQuery( '#nav-bar' ).removeClass( 'scroll' );
	}); */

});





	/* jQuery('#featured-posts img').ready(function() {
		alert('aaxxx');
		//jQuery(this).parent().parent().show();
	}); */


/* load fb like box with ajax */
function loadFaceBox(){
 jQuery('#fbcont').append(jQuery('<iframe>')
        .attr({
 'src':"http://www.facebook.com/connect/connect.php?id=154652601231841\u0026connections=10\u0026stream=0\u0026colorscheme=light\u0026width=300\u0026height=163",
 'frameborder':"0",
 'width':"320",
 'height':"163",
 'scrolling': 'no',
 'allowTransparency': 'true',
 'style': "border:none; overflow:hidden; width:320px; height:163px;"
        })
     );
}


/* Pretty content scroll */
function goToByScroll(id){
     	jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top},'slow');
}

/* carousel handle image loading */
function addictiveLoadImages( instance, item, idx, state ){
	if( state != 'init' ){
		if( idx > 3 ){
			if( jQuery( 'img', item ).attr( 'src') == '' ){
				jQuery( 'img', item ).attr( 'src', jQuery( 'img', item ).attr('holder-src') );
			}
		}
	}
}


//SHAREBAR FIXED
	jQuery(document).ready(function(){
          //var topPos = jQuery('article .entry-content').offset().top + 2;
	  var topPos = jQuery('article .entry-content').position().top + 2;
	  jQuery('.dd_outer').css('top',topPos);
	  //jQuery('.dd_outer').css('top',topPos);
	  jQuery('.dd_outer').css('display', 'block');

	  if(jQuery(window).width() < 1024){
			  //do nothing
			} else {
				if (jQuery(window).scrollTop() > 200 ){
					//jQuery(' #large-buttons').css('display','block');
				}
			}
			jQuery(window).bind('resize', function(){
				if(jQuery(window).width() < 1024){
					jQuery('.dd_outer').css('display','none');
				} else {
					//if (jQuery(window).scrollTop() > 200){
					  jQuery('.dd_outer').css('display','block');
					//}
				}
			});
			jQuery(window).scroll(function(){
				if (jQuery(window).height() + jQuery(window).scrollTop() >= jQuery(document).height()- 355 ){
					jQuery('.dd_outer').css('height','0');
					jQuery('.dd_outer').css('overflow','hidden');
					//jQuery('#large-buttons').css('display','none');
				}
				else {
					//jQuery('#large-buttons').css('display','block');
					jQuery('.dd_outer').css('height','auto');
					jQuery('.dd_outer').css('overflow','visible');
					}
				if (jQuery(window).scrollTop() > 200 && jQuery(window).width() > 1024 ){
					//jQuery('#large-buttons').css('display','block');
				}

			});

	})

//SHAREBAR FIXED
